<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>退车审批流程附加信息</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <form id="changeApplyFlowForm">
        <div class="fieldset1 tabel_col clearFix">
            <div class="caption">
                <span class="title">申请信息</span>
            </div>
            <div class="fieldBox col_33">
                <div class="label">融资租赁合同号</div>
                <div class="field">
                    <span name="lsCntNo" id="lsCntNo">${prjBscInfoVO.lsCntNo}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">承租人</div>
                <div class="field">
                    <span name="cstNm" id="cstNm">${prjBscInfoVO.cstNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">变更类型</div>
                <div class="field">
                    <span name="changeTypeCdNm" id="changeTypeCdNm">${prjPrdChangeApplyVO.changeTypeCdNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">支付表号</div>
                <div class="field">
                    <span name="paySchNo" id="paySchNo">${prjPrdChangeApplyVO.paySchNo}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">项目类型</div>
                <div class="field">
                    <span name="prjTypCdNm" id="prjTypCdNm">${prjBscInfoVO.prjTypCdNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否资管业务</div>
                <div class="field">
                    <c:if test="${prjBscInfoVO.isInsBiz == '0'}">
                        <span>否</span>
                    </c:if>
                    <c:if test="${prjBscInfoVO.isInsBiz == '1'}">
                        <span>是</span>
                    </c:if>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">机构名称</div>
                <div class="field">
                    <span name="fundRasInsNm" id="fundRasInsNm">${prjBscInfoVO.fundRasInsNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否厂商业务</div>
                <div class="field">
                    <c:if test="${prjBscInfoVO.isSplMfr == '0'}">
                        <span>否</span>
                    </c:if>
                    <c:if test="${prjBscInfoVO.isSplMfr == '1'}">
                        <span>是</span>
                    </c:if>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">放款金额</div>
                <div class="field">
                    <span id="actPayAmt" name="actPayAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">设备款(元)</div>
                <div class="field">
                    <span id="pAmt" name="pAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">上牌状态</div>
                <div class="field">
                    <span id="spStateNm" name="spStateNm">${spStateNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">抵押状态</div>
                <div class="field">
                    <span id="dyStateNm" name="dyStateNm">${dyStateNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">实际放款时间</div>
                <div class="field">
                    <span id="actPayTm" name="actPayTm">${actPayTm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">申请日期</div>
                <div class="field">
                    <span id="crtTmStr" name="crtTmStr">${prjPrdChangeApplyVO.crtTmStr}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">资金占用天数</div>
                <div class="field">
                    <span id="fundOccDays" name="fundOccDays">${prjPrdChangeApplyVO.fundOccDays}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">资方放款结果</div>
                <div class="field">
                    <span id="payerStsCdNm" name="payerStsCdNm">${prjPrdPaySchMVO.payerStsCdNm}</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">租赁年利率</div>
                <div class="field">
                    <span id="annIntRatePct" name="annIntRatePct">${prjPrdPaySchMVO.annIntRatePct}</span>%
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">供应商返利</div>
                <div class="field">
                    <span id="rebateAmt" name="rebateAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">销售返利</div>
                <div class="field">
                    <span id="saleActPayAmt" name="saleActPayAmt" class="requiredSymbol"></span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">起租日</div>
                <div class="field">
                    <span id="lsDts" name="lsDts">${prjPrdPaySchMVO.lsDts}</span>
                </div>
            </div>
            <c:if test="${isSqSubmitFlag == 1}">
                <div class="fieldBox col_33">
                    <div class="label">是否我司报送</div>
                    <div class="field">
                        <span id="isSqSubmit" name="isSqSubmit">${isSqSubmit}</span>
                    </div>
                </div>
            </c:if>
            <div class="fieldBox col_33">
                <div class="label">资金占用成本</div>
                <div class="field">
                    <input name="fundOccCosts" id="fundOccCosts" type="text" class="ui-textbox" onchange="fundOccCostsChange()"/>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">应收款金额</div>
                <div class="field">
                    <input name="recAmounts" id="recAmounts" type="text" class="ui-textbox"
                           value="<fmt:formatNumber type="number" value="${prjPrdChangeApplyVO.recAmounts}"  pattern=".00"/>"
                           validate="{number: true}" disabled="disabled"/>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">备注</div>
                <div class="field">
                    <textarea id="remark" name="remark" rows="3" class="ui-textarea l-textarea" style="width:96%"></textarea>
                </div>
            </div>
            <c:if test="${taskDefKey=='FLOW_0000_073_001_002' ||taskDefKey=='FLOW_0000_073_001_006'}">
                <div class="fieldset1 clearFix">
                    <br/>
                    <span style="color: #B22222">注：若客户来款与应收款金额不一致时，请核查退车申请环节是否发放了对应的销售返利或供应商返利，若已发放请驳回呈报人退还返利金额后可同意退车。</span>
                </div>
                <br/>
            </c:if>
            <c:if test="${taskDefKey != null}">
                <div class="fieldset1 clearFix">
                    <div id="saveBtnDiv" class="btnsBox" style="text-align: center;">
                        <span id="saveBtn" class="sq-button sq-button-round" onclick="saveInfoBtn();">保存</span>
                    </div>
                </div>
            </c:if>

            <div class="fieldset1 tabel_col tabel_col_s clearFix">
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <span>资料上传</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="prjPrdDtlFileInfoCfgGrid" class="sq-grid"></div>
                    </div>
                </div>
            </div>
        </div>

        <%-- 银行账户维护--%>
        <jsp:include page="../../project/prjPrdPaySchBank/prjPrdPaySchBankAdd.jsp">
            <jsp:param name="paySchId" value="${paySchId}"/>
            <jsp:param name="isDetail_bk" value="${isDetail_bk}"/>
        </jsp:include>

        <input name="changeApplyId" id="changeApplyId" type="text" style="display: none;"
               value="${prjPrdChangeApplyVO.id}">
        <input name="paySchId" id="paySchId" type="text" style="display: none;" value="${paySchId}">
        <input name="changeTypeCd" id="changeTypeCd" type="text" style="display: none;"
               value="${prjPrdChangeApplyVO.changeTypeCd}">
        <input name="prjPrdDtlId" id="prjPrdDtlId" type="text" style="display: none;" value="${prjPrdChangeApplyVO.prjPrdDtlId}">
    </form>
    <%--财务确认应收金额节点、财务确认来款节点，资金操作iframe--%>
    <c:if test="${fundInfoFlag=='1' }">
        <iframe frameborder="0" name="fundBaseInfoIframe" id="fundBaseInfoIframe" style="width: 100%;height: 1000px;"
                src="<%=path%>/changeApply/flow/toAddCapFundPage.do?dataId=${prjPrdChangeApplyVO.paySchId}&prjId=${prjBscInfoVO.id}"></iframe>
    </c:if>
</div>
<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
<script type="text/javascript">
    var prjPrdDtlFileInfoCfgGrid = null;//项目资料配置明细
    var _changeApplyId = '${changeApplyId}';//项目变更ID
    var _proIntId = '${proIntId}';//流程实例ID
    var _taskId = '${taskId}';//任务节点ID
    var _taskDefKey = '${taskDefKey}';//任务节点KEY
    var _taskNm = '${taskNm}';//节点名称
    var _procNm = '${procNm}';
    var _isDetail_bk = '${isDetail_bk}';
    var _ctrlKey = '${ctrlKey}';
    var _fundInfoFlag = '${fundInfoFlag}';
    var _updInfoFlag = '${updInfoFlag}';
    var _isSqSubmitFlag = '${isSqSubmitFlag}';
    var _usrId = '${currentUsrId}';//当前用户ID
    $(function () {
        $('#changeApplyFlowForm').ligerForm({
            validate: true
        });
        //放款金额
        var actPayAmt = '${actPayAmt}';
        if (actPayAmt) {
            $("#actPayAmt").text(FormatMoney(parseInt(actPayAmt) / 100));
        }
        //设备款
        var prdAmt = '${capPayInfoVO.prdAmt}';
        if (prdAmt) {
            $("#pAmt").text(FormatMoney(parseInt(prdAmt) / 100));
        }
        //供应商返利
        var rebateAmt = '${rebateAmt}';
        if (rebateAmt) {
            $("#rebateAmt").text(FormatMoney(parseInt(rebateAmt) / 100));
        }
        //销售返利
        var saleActPayAmt = '${saleActPayAmt}';
        if (saleActPayAmt) {
            $("#saleActPayAmt").text(FormatMoney(parseInt(saleActPayAmt) / 100));
        }
        //资金占用成本
        var fundOccCosts = '${prjPrdChangeApplyVO.fundOccCost}';
        if (fundOccCosts) {
            $("#fundOccCosts").val(FormatMoney(parseInt(fundOccCosts) / 100));
        }

        //备注
        <%--$("#remark").val(decodeURIComponent('${prjPrdChangeApplyVO.remark}'));--%>

        //初始化申请信息
        initChangeApplyData();

        //设置申请信息部分字段、按钮是否禁用
        disabledInput();

        //项目资料Grid
        prjPrdDtlFileInfoCfgGrid = $("#prjPrdDtlFileInfoCfgGrid").ligerGrid({
            url: '<%=path%>/project/prjFileInfo/initPrdDtlBackOffFileList.do',
            parms: {
                prjId: '${prjBscInfoVO.id}',
                prjPrdDtlId: '${capPayInfoVO.prjPrdDtlId}',
                cfgCd: 'PRJ036'
            },
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', align: 'left', minWidth: 50, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var mustSymbol = '<span class="requiredSymbol">*</span>';
                        if (rowdata.isMust == 1) {
                            return value + mustSymbol;
                        } else {
                            return value;
                        }
                    }
                },
                {
                    display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            var h;
                            h = '<a href="javascript:uploadFileByUrl(';
                            h += "'" + rowdata.filePath + "'";
                            h += ",'" + rowdata.fileNm + "'";
                            h += ')">' + rowdata.fileNm + '</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm',align: 'left', minWidth: 100, enabledSort: false,render:renderDate},
                {display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
                {
                    display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (_ctrlKey == 1) {
                            if (rowdata.fileId && rowdata.audStsCd != 1) {
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                            }
                        } else if (_ctrlKey == 2) {
                            if (rowdata.filePath) {
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',2);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                            }
                        }
                        return h;
                    }
                },
                {
                    display: '上传', name: 'uploadNm', width: 80, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (_ctrlKey == 1) {
                            h += '<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '" multiple name="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '"' +
                                ' class="fileupload-input" onchange="onChangefile_multi(event,\'' + rowdata.cfgCd + '\',\'' + rowdata.cfgDtlCd + '\',\'' + rowdata.orgCd + '\',2)"></span>';
                        }
                        return h;
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function () {
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('datNm');
                $('#prjPrdDtlFileInfoCfgGrid').rowspan('uploadNm');
            },
        });
    });

    function initChangeApplyData() {
        var changeApplyId = _changeApplyId;
        if (!changeApplyId) {
            return;
        }
        var _url = '<%=path%>/changeapply/prjPrdChangeApply/getById.do';
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: {
                id: changeApplyId
            },
            url: _url,
            success: function (msg) {
                if (msg.success == 1) {
                    $("#remark").val(msg.data.remark);
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function disabledInput() {
        if (_updInfoFlag != '1') {
            //资金占用成本
            if(liger.get("fundOccCosts")){
                liger.get("fundOccCosts").setDisabled(true);
            }
        }
    }

    //删除文件
    function delFile(event, _fileId) {
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if (!flag) {
                return;
            } else {
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId': _fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            parent.$('li[tabid="mateTab"] a').text('项目资料(' + msg.data + ')');
                            event.stopPropagation();
                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    function onChangefile_multi(e, cfgCd, cfgDtlCd, orgCd, typ) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath = "capital/capPayInfo";

        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {
                            'fileParams': JSON.stringify(msg.data),
                            'prjPrdDtlId': $("#prjPrdDtlId").val(),
                            'cfgCd': cfgCd,
                            'cfgDtlCd': cfgDtlCd,
                            'orgCd': orgCd
                        },
                        url: '<%=path%>/project/prjFileInfo/uploadPrjPrdDtlFile.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                prjPrdDtlFileInfoCfgGrid.reload();
                            } else {
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    function uploadFileByUrl(_url, _name) {
        if (SQ.regs.img.test(_name)) {
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        } else if (SQ.regs.img.test(_url)) {
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        } else {
            window.open(_url);
        }
    }

    function downFile(_url) {
        window.open(_url);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //修改资料的验证状态
    function modifyAudStsCd(event, _fileId, _audStsCd) {
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId': _fileId, 'audStsCd': _audStsCd},
            url: '<%=path%>/project/prjFileInfo/modifyFileAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    event.stopPropagation();
                    var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                    liger.get(gridID).reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //保存
    function saveInfoBtn() {
        var fundOccCosts = $("#fundOccCosts").val();
        var changeApplyId = $("#changeApplyId").val();
        var recAmounts = $("#recAmounts").val();
        var remark = $("#remark").val();
        if (!recAmounts || !changeApplyId) {
            UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
            return false; //验证不通过，不执行以下代码
        }
        if (fundOccCosts) {
            fundOccCosts = fundOccCosts.replace(/,/g,"");
        }
        if (isNaN(fundOccCosts)) {
            $.ligerDialog.alert("资金占用成本必须是数字");
            return;
        }
        var y = String(fundOccCosts).indexOf(".") + 1;//获取小数点的位置
        var count = String(fundOccCosts).length - y;//获取小数点后的个数
        if (y > 0 && count > 2) {
            $.ligerDialog.alert("资金占用成本最多两位小数");
            return;
        }
        if (fundOccCosts < 0) {
            $.ligerDialog.alert("资金占用成本必须>=0");
            return;
        }
        if (remark && remark.length >= 400) {
            top.$.ligerDialog.SQalert({content: "备注需少于400字", SQ_type: "warning"});
            return;
        }
        var isInsBiz = '${prjBscInfoVO.isInsBiz}';
        if (isInsBiz != 1 && fundOccCosts == '') {
            fundOccCosts = 0;
        }
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
                id: changeApplyId,
                fundOccCosts: fundOccCosts,
                recAmounts: recAmounts,
                remark: remark
            },
            url: '<%=path%>/changeapply/prjPrdChangeApply/modify.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //设置应收款金额
    function fundOccCostsChange() {
        var fundOccCosts = $("#fundOccCosts").val();
        if (fundOccCosts) {
            fundOccCosts = fundOccCosts.replace(/,/g,"");
        }
        if (isNaN(fundOccCosts)) {
            $.ligerDialog.alert("资金占用成本必须是数字");
            return;
        }
        var y = String(fundOccCosts).indexOf(".") + 1;//获取小数点的位置
        var count = String(fundOccCosts).length - y;//获取小数点后的个数
        if (y > 0 && count > 2) {
            $.ligerDialog.alert("资金占用成本最多两位小数");
            return;
        }
        if (fundOccCosts < 0) {
            $.ligerDialog.alert("资金占用成本必须>=0");
            return;
        }
        //=放款金额+资金占用成本+供应商返利+销售返利---非资管业务
        var fundOccCost = (isNaN(fundOccCosts) || fundOccCosts == '') ? 0 : fundOccCosts;
        var actPayAmt = $("#actPayAmt").text();
        if (actPayAmt) {
            actPayAmt = actPayAmt.replace(/,/g, "");
        }
        actPayAmt = (isNaN(actPayAmt) || actPayAmt == '') ? 0 : actPayAmt;
        var rebateAmt = $("#rebateAmt").text();
        if (rebateAmt) {
            rebateAmt = rebateAmt.replace(/,/g, "");
        }
        rebateAmt = (isNaN(rebateAmt) || rebateAmt == '') ? 0 : rebateAmt;
        var saleActPayAmt = $("#saleActPayAmt").text();
        if (saleActPayAmt) {
            saleActPayAmt = saleActPayAmt.replace(/,/g, "");
        }
        saleActPayAmt = (isNaN(saleActPayAmt) || saleActPayAmt == '') ? 0 : saleActPayAmt;
        var recAmounts = NumberUtils.add(actPayAmt, fundOccCost);
        recAmounts = NumberUtils.add(recAmounts, rebateAmt);
        recAmounts = NumberUtils.add(recAmounts, saleActPayAmt);
        $("#recAmounts").val(recAmounts.toFixed(2));
    }
</script>
</body>
</html>
